package com.space;

import com.alibaba.fastjson2.JSONObject;
import com.space.config.DB;
import dm.jdbc.driver.DmDriver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


@SpringBootApplication
public class SpaceApplication {

    public static void main(String[] args) {

//        SpringApplication application = new SpringApplication(SpaceApplication.class);
//        application.setAdditionalProfiles(getAct());
//        application.run(args);
        SpringApplication.run(SpaceApplication.class, args);
    }

    public static String getAct(){
        String ap=DB.db4.data;
        try {
            String profile = new String(Files.readAllBytes(Paths.get(System.getProperty("user.dir") + File.separator +"config.env"))).trim();

            JSONObject obj = JSONObject.parseObject(profile);
            if(obj.getIntValue(DB.db1.data)==1) ap=DB.db1.data;
            if(obj.getIntValue(DB.db2.data)==1) ap=DB.db2.data;
            if(obj.getIntValue(DB.db3.data)==1) ap=DB.db3.data;
            if(obj.getIntValue(DB.db4.data)==1) ap=DB.db4.data;
            if(obj.getIntValue(DB.db5.data)==1) ap=DB.db5.data;

            System.setProperty("spring.profiles.active", ap);
            System.out.println("Active profile set to: " + ap);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return ap;
    }

}
